import axios from 'axios';
import { complaint_type, consultation_type, getDictData ,goodType,goodNewType, payment_method_type, loading_unloading_mode, vehicle_new_type } from '@/api/index';

let dictUtil = {

};

// 获取常用的数据字典保存至vuex
dictUtil.initDictData = function (vm) {
    axios.get(getDictData + "/sex").then(res => {
        if (res.success) {
            vm.$store.commit("setSex", res.result);
        }
    });
    axios.get(getDictData + "/vehicle_type").then(res => {
        if (res.success) {
            vm.$store.commit("setVehicleType", res.result);
            window.localStorage.setItem('vehicle_type', JSON.stringify(res.result));
        }
    });
    axios.get(getDictData + "/message_type").then(res => {
        if (res.success) {
            vm.$store.commit("setMessageType", res.result);
            window.localStorage.setItem('message_type', JSON.stringify(res.result));
        }
    });

    axios.get(goodNewType).then(res => {
        if (res.success) {
            window.localStorage.setItem('good_new_type', JSON.stringify(res.result));
        }
    });
    
    axios.get(goodType).then(res => {
        if (res.success) {
            window.localStorage.setItem('good_type', JSON.stringify(res.result));
        }
    });
    axios.get(payment_method_type).then(res => {
        if (res.success) {
            // vm.$store.commit("payment_method_type", res.result);
            window.localStorage.setItem('payment_method_type', JSON.stringify(res.result));
        }
    });

    axios.get(loading_unloading_mode).then(res => {
        if (res.success) {
            // vm.$store.commit("payment_method_type", res.result);
            window.localStorage.setItem('loading_unloading_mode', JSON.stringify(res.result));
        }
    });
    axios.get(vehicle_new_type).then(res => {
        if (res.success) {
            window.localStorage.setItem('vehicle_new_type', JSON.stringify(res.result));
        }
    });
    axios.get(consultation_type).then(res => {
        if (res.success) {
            window.localStorage.setItem('consultation_type', JSON.stringify(res.result));
        }
    });
    axios.get(complaint_type).then(res => {
        if (res.success) {
            window.localStorage.setItem('complaint_type', JSON.stringify(res.result));
        }
    });

};

export default dictUtil;
